package com.stb.client.menu;

import com.google.gwt.user.client.ui.MenuBar;
import com.stb.client.menu.listener.LogoffListener;
import com.stb.client.menu.listener.LogonListener;
import com.stb.client.session.UserSession;

public class MainMenu extends MenuBar implements LogonListener, LogoffListener {
	
	private final RegisterUserItem registerUserItem = new RegisterUserItem();
	private final LogonItem logonItem = new LogonItem(this);
	private final LogoffItem logoffItem = new LogoffItem(this);
	
	public MainMenu() {
		MenuBar userMenu = new MenuBar(true);
    	this.addItem("User", userMenu);
    	userMenu.addItem(this.registerUserItem);
		userMenu.addItem(this.logonItem);
		userMenu.addItem(this.logoffItem);
		this.logoffItem.setEnabled(false);
	}

	@Override
	public void loggedOn(String sessionId) {
		UserSession.INSTANCE.setSessionId(sessionId);
		this.logonItem.setEnabled(false);
		this.logoffItem.setEnabled(true);
	}

	@Override
	public void loggedOff() {
		UserSession.INSTANCE.clear();
		this.logonItem.setEnabled(true);
		this.logoffItem.setEnabled(false);
	}
}
